local skel = fk.CreateSkill {
  name = "rmt__zhunshi",
}

Fk:loadTranslationTable{
  ["rmt__zhunshi"] = "谆士",
  [":rmt__zhunshi"] = "你于回合外摸牌后，可以令当前回合角色摸一张牌；你于回合外回复体力后，可以令当前回合角色回复等量体力。你均如此做过的回合结束后，你执行一个额外回合。",

  ["@@rmt__zhunshi-turn"] = "谆士:额外回合",
  ["#rmt__zhunshi-recover"] = "谆士：你可以令 %dest 回复 %arg 点体力",
  ["#rmt__zhunshi-draw"] = "谆士：你可以令 %dest 摸一张牌",

  ["$rmt__zhunshi1"] = "诲尔谆谆，听我藐藐；驰慢不一，难堪大任。",
  ["$rmt__zhunshi2"] = "乱父子纲常，坏圣人之道，讵不谆哉？",
}


skel:addEffect(fk.AfterCardsMove, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    local current = player.room.current
    if current and current ~= player and not current.dead then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Player.Hand and move.moveReason == fk.ReasonDraw then
          return true
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local current = room.current
    if room:askToSkillInvoke(player, {
      skill_name = skel.name, prompt = "#rmt__zhunshi-draw::"..current.id
    }) then
      event:setCostData(self, {tos = {current}})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local current = room.current
    current:drawCards(1, skel.name)
    room:setPlayerMark(player, "rmt__zhunshi1-turn", 1)
    if player:getMark("rmt__zhunshi1-turn") == 1 and player:getMark("rmt__zhunshi2-turn") == 1 then
      room:setPlayerMark(player, "@@rmt__zhunshi-turn", 1)
    end
  end,
})

skel:addEffect(fk.HpRecover, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    if target == player then
      local current = player.room.current
      return current and current ~= player and not current.dead-- and current:isWounded()
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local current = room.current
    if room:askToSkillInvoke(player, {
      skill_name = skel.name, prompt = "#rmt__zhunshi-recover::"..current.id..":"..data.num
    }) then
      event:setCostData(self, {tos = {current}})
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local current = room.current
    room:recover { num = data.num, skillName = skel.name, who = current, recoverBy = player }
    room:setPlayerMark(player, "rmt__zhunshi2-turn", 1)
    if player:getMark("rmt__zhunshi1-turn") == 1 and player:getMark("rmt__zhunshi2-turn") == 1 then
      room:setPlayerMark(player, "@@rmt__zhunshi-turn", 1)
    end
  end,
})

skel:addEffect(fk.TurnEnd, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return false end
    return player:getMark("@@rmt__zhunshi-turn") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    player:gainAnExtraTurn(true, skel.name)
  end,
})

return skel
